package com.mc.moring.main;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import com.mc.moring.widge.InformationConfirmarDialog;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.mc.moring.R;
import com.mc.moring.app.LogUtils;
import com.mc.moring.base.BaseActivity;
import com.mc.moring.base.HttpCallback;
import com.mc.moring.bean.SingleSelectBean;
import com.mc.moring.bean.ZiLiPageUserDataBean;
import com.mc.moring.information.CapitalInforActivity;
import com.mc.moring.information.modle.KycModle;
import com.mc.moring.main.adapter.SingleChooseAdapter;
import com.mc.moring.main.modle.LoanModle;
import com.mc.moring.util.T;
import com.mc.moring.util.ToastUtils;
import com.mc.moring.widge.SingleSelectDialogView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AddBandActivity extends BaseActivity {
    LinearLayout dialog_background;
    RecyclerView account_type_rv, bank_name_rv;
    private SingleChooseAdapter account_type_rv_adapter, bank_name_rv_adapter;
    public KycModle kycModle = null;
    FrameLayout fl_bank_name;
    TextView et_bank_name;
    FrameLayout fl_account_type;
    TextView et_account_type;

    TextView tv_tip;

    LinearLayout lly_bottom_tips;
    EditText et_account_number;
    String bankCode, accountType, mNationalId;
    private JSONArray bankJa;

    private RelativeLayout rlAddBank;

    private ImageButton abBackIBtn;
    private TextView abTitleTV;
    private LinearLayout ll_account_type_rv;
    private LinearLayout ll_bank_name_rv;
    TextView tv_sub_to, tv_bank_name_err, tv_account_number_err;
    View number_line;
    View bank_line;

    View view = null;

    private Context mContext;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtils.logE("add bank card page");
        mContext = this;
        setContentView(R.layout.activity_add_band);
        dialog_background = findViewById(R.id.dialog_background);
        view = findViewById(R.id.rl_all_add_bank);
        kycModle = KycModle.Companion.getInstant();
        tv_sub_to = findViewById(R.id.tv_sub_to);
        tv_account_number_err = findViewById(R.id.tv_account_number_err);
        number_line = view.findViewById(R.id.number_line);
        tv_bank_name_err = findViewById(R.id.tv_bank_name_err);
        bank_line = view.findViewById(R.id.bank_line);
        fl_bank_name = findViewById(R.id.fl_bank_name);
        ll_account_type_rv = findViewById(R.id.ll_account_type_rv);
        ll_bank_name_rv = findViewById(R.id.ll_bank_name_rv);
        bank_name_rv = findViewById(R.id.bank_name_rv);
        et_bank_name = findViewById(R.id.et_bank_name);
        fl_account_type = findViewById(R.id.fl_account_type);
        et_account_type = findViewById(R.id.et_account_type);
        et_account_number = findViewById(R.id.et_account_number);
        abBackIBtn = findViewById(R.id.abBackIBtn);
        abTitleTV = findViewById(R.id.abTitleTV);
        abTitleTV.setText("Vincule su cuenta");
        abBackIBtn.setOnClickListener(v -> finish());
        account_type_rv = findViewById(R.id.account_type_rv);
        account_type_rv.setLayoutManager(new LinearLayoutManager(AddBandActivity.this));
        tv_tip = view.findViewById(R.id.tv_tip);
        lly_bottom_tips = view.findViewById(R.id.lly_bottom_tips);

        et_account_type.setText("RUT");
        accountType = "3";
        et_bank_name.setText("Banco Estado (Banco del Estado de Chile)");
        setDefaultBankCode();
        et_account_number.setInputType(InputType.TYPE_CLASS_TEXT);
//        et_account_number.addTextChangedListener(new CommonTextWatcher(et_account_number, tv_account_number_err));
        getZiLiPageUserFullInfo(true);
        checkAccountNumber();

        bank_name_rv.setLayoutManager(new LinearLayoutManager(AddBandActivity.this));
        bank_name_rv_adapter = new SingleChooseAdapter();
        bank_name_rv.setAdapter(bank_name_rv_adapter);
        bank_name_rv_adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (view.getId() == R.id.ll) {
                    et_bank_name.setText(bank_name_rv_adapter.getData().get(position).getText());
                    bankCode = String.valueOf(bank_name_rv_adapter.getData().get(position).getId());
                    ll_bank_name_rv.setVisibility(View.GONE);
                }
            }
        });
        et_account_number.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                Log.e("----char",charSequence.toString());
                if ( et_account_type.getText().toString().equals("RUT") ){
                    if ( charSequence.length() >= 7 ){
                        tv_account_number_err.setVisibility(View.GONE);
                        number_line.setBackgroundColor(Color.parseColor("#33000000"));
                    }
                } else {
                    if ( charSequence.length() >= 8 ){
                        tv_account_number_err.setVisibility(View.GONE);
                        number_line.setBackgroundColor(Color.parseColor("#33000000"));
                    }
                }

            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        fl_bank_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                getZiLiPagePayBankList();
                tv_account_number_err.setVisibility(View.GONE);
                number_line.setBackgroundColor(Color.parseColor("#33000000"));
                if (et_account_type.getText().equals("RUT") &&
                        et_bank_name.getText().equals("Banco Estado (Banco del Estado de Chile)")) {
                    tv_tip.setVisibility(View.VISIBLE);
                    tv_tip.setText("\nPara garantizarquelacuenta receptora sea consistente con la persona concédula de identidad, la cuenta RUT no admite modificación, se puede elegir otra cuenta bancaria para recibir el pago.");
                    tv_tip.setTextColor(Color.parseColor("#FFB307"));
                    Log.e("----","006");
                } else {
                    tv_tip.setVisibility(View.GONE);
                }
            }
        });
        fl_account_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        selectZiLiPageTipoDeCuenta();
                    }
                });
                tv_account_number_err.setVisibility(View.GONE);
                number_line.setBackgroundColor(Color.parseColor("#33000000"));
                if (et_account_type.getText().equals("RUT") &&
                        et_bank_name.getText().equals("Banco Estado (Banco del Estado de Chile)")) {
                    tv_tip.setVisibility(View.VISIBLE);
                    tv_tip.setText("\nPara garantizarquelacuenta receptora sea consistente con la persona concédula de identidad, la cuenta RUT no admite modificación, se puede elegir otra cuenta bancaria para recibir el pago.");
                    tv_tip.setTextColor(Color.parseColor("#FFB307"));
                    Log.e("----","006");
                } else {
                    tv_tip.setVisibility(View.GONE);
                }
            }
        });

        tv_sub_to.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtils.logE("---111-bankCode:"+bankCode);
                if (TextUtils.isEmpty(bankCode)) {
                    tv_bank_name_err.setVisibility(View.VISIBLE);
                    bank_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                } else {
                    tv_bank_name_err.setVisibility(View.GONE);
                    bank_line.setBackgroundColor(Color.parseColor("#33000000"));
                }

                String accountStr = et_account_number.getText().toString();

                String account_type = et_account_type.getText().toString();
                if (account_type != null) {
                    if (account_type.equals("Cuenta ahorro") || account_type.equals("Cuenta corriente")
                            || account_type.equals("Vista")) {
                        if (!verificationBankAccountBase(8,20, accountStr)) {
                            tv_account_number_err.setVisibility(View.VISIBLE);
                            tv_account_number_err.setText("Error, introduzca un número puro de 8 - 20 dígitos");
                            number_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                            return;
                        } else {
                            tv_account_number_err.setVisibility(View.GONE);
                            number_line.setBackgroundColor(Color.parseColor("#33000000"));
                        }
                    } else if (account_type.equals("RUT")) {

                        if (accountStr.length()<7 ||accountStr.length() >9) {
                            tv_account_number_err.setVisibility(View.VISIBLE);
                            tv_account_number_err.setText("Error, introduzca un número puro de 7 - 9 dígitos");
                            number_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                            Log.e("----","004");
                            return;
                        } else {
                            tv_account_number_err.setVisibility(View.GONE);
                            number_line.setBackgroundColor(Color.parseColor("#33000000"));
                            Log.e("----","02");
                        }
                    }
                } else {
                    tv_account_number_err.setVisibility(View.VISIBLE);
                    tv_account_number_err.setText("Por favor, elija nombre bancaria");
                    number_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                }
                InformationConfirmarDialog myDialog = new InformationConfirmarDialog(AddBandActivity.this, et_account_number.getText().toString().trim());
                myDialog.setDialogViewOnClickListener(new InformationConfirmarDialog.DialogViewOnClickListener() {
                    @Override
                    public void onClickConfirm() {
                        myDialog.dismiss();
                        dealWithSubData();
                    }

                    @Override
                    public void onClickCancel() {
                        myDialog.dismiss();
//                                                        goMain(data);
                    }
                });
                myDialog.showToPermissionSettingDialog(AddBandActivity.this);
            }
        });
    }

    private void dealWithSubData(){

        Map<String, String> params = new HashMap<String, String>();
        //      params.put("bankId", "");
        params.put("bankCode", bankCode);
        if (et_account_type.getText().equals("RUT")
                && et_bank_name.getText().equals("Banco Estado (Banco del Estado de Chile)")) {
            if (!TextUtils.isEmpty(mNationalId)) {
                params.put("accountNumber", mNationalId);
            } else {
                params.put("accountNumber", et_account_number.getText().toString());
            }
        } else {
            params.put("accountNumber", et_account_number.getText().toString());
        }
        LogUtils.logE("params 111--et_account_type-et_account_type.getText()-->"+et_account_type.getText().toString());
        params.put("accountType", accountType);
        params.put("scenes", "info");
        LogUtils.logE("sss params>>>" + new Gson().toJson(params));
//        showLoading();
        LoanModle.Companion.getInstant().bankbindAccount(params, new HttpCallback() {
            @Override
            public void onSuccess(@NonNull String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        LogUtils.logE("final submit success 1>" + data);
                        try {
                            JSONObject jsonObject = new JSONObject(data);
                            if (kycModle.getStringToJson(jsonObject, "code").equals("0000")) {
                                Intent intent = new Intent();
                                intent.putExtra("refresh", true);
                                setResult(Activity.RESULT_OK, intent);
                                finish();
                            } else {

                                new Handler(Looper.getMainLooper()).post(new Runnable() {
                                    @Override
                                    public void run() {
                                        ToastUtils.showShort(AddBandActivity.this, kycModle.getStringToJson(jsonObject, "msg"));
                                    }
                                });

                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

//                hideLoading();
            }

            @Override
            public void onFaill(@NonNull String e) {

//                hideLoading();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        LogUtils.logE("submit fail>" + e);
                    }
                });
            }
        });
    }

    @Override
    public Activity getActivity() {
        return null;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    public void getZiLiPagePayBankList() {
        if (bankJa != null && bankJa.length() > 0) {
            showSelectBank(bankJa);
            return;
        }
        Map<String, String> params = new HashMap<String, String>();
//        showLoading();
        kycModle.getZiLiPagePayBankList(params, new HttpCallback() {
            @Override
            public void onSuccess(@NonNull String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            JSONObject jsonObject = new JSONObject(data);
                            if (kycModle.isSuccess(jsonObject)) {
                                JSONArray dataJa = jsonObject.optJSONArray("data");
                                if (dataJa != null) {
                                    showSelectBank(dataJa);
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

//                hideLoading();
            }

            @Override
            public void onFaill(@NonNull String e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        T.showShort(AddBandActivity.this, e);
                    }
                });

//                hideLoading();
            }
        });

    }

    private void selectZiLiPageTipoDeCuenta() {
        List<SingleSelectBean> selectBeanList = new ArrayList<>();
        List<String> values = new ArrayList<>();
        values.add("Cuenta ahorro");
        values.add("Cuenta corriente");
        values.add("Vista");
        values.add("RUT");
        for (int i = 0; i < values.size(); i++) {
            SingleSelectBean singleSelectBean = new SingleSelectBean();
            singleSelectBean.setId(i);
            singleSelectBean.setText(values.get(i));
            singleSelectBean.setCheck(false);
            selectBeanList.add(singleSelectBean);
        }
        showProfession(selectBeanList, 2, "Tipo de cuenta");
    }

    private void showSelectBank(JSONArray dataJa) {
        this.bankJa = dataJa;
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                List<SingleSelectBean> selectBeanList = new ArrayList<>();
                for (int i = 0; i < dataJa.length(); i++) {
                    JSONObject jsonObject = dataJa.optJSONObject(i);
                    SingleSelectBean selectBean = new SingleSelectBean();
                    selectBean.setText(kycModle.getStringToJson(jsonObject, "bankName"));
                    selectBean.setCode(kycModle.getStringToJson(jsonObject, "bankCode"));
                    selectBean.setId(i);
                    selectBean.setCheck(false);
                    selectBeanList.add(selectBean);
                }
                showProfession(selectBeanList, 1, "Nombre del banco");
            }
        });
    }

    private void showProfession(List<SingleSelectBean> dataList, int key, String title) {
        SingleSelectDialogView dialogView = new SingleSelectDialogView(mContext, view, title);
        dialogView.setSingleSelectListener(new SingleSelectDialogView.SingleSelectListener() {
            @Override
            public void checked(SingleSelectBean s) {
                if (key == 1) {
                    if (et_bank_name.getText() == s.getText()) {
                        dialogView.dismiss();
                        dialog_background.setVisibility(View.GONE);
                        return;
                    } else {
                        et_bank_name.setText(s.getText());
                        bankCode = s.getCode();
                        et_account_type.setText("Cuenta ahorro");
                        setAccountType();
                        et_account_number.setHint("Seleccione su región");
                    }
                } else if (key == 2) {
                    if (et_account_type.getText() == s.getText()) {
                        dialogView.dismiss();
                        dialog_background.setVisibility(View.GONE);
                        return;
                    } else {
                        et_account_type.setText(s.getText());
                        setAccountType();
                    }
                }
                et_account_number.setText("");
                checkAccountNumber();
                dialogView.dismiss();
                dialog_background.setVisibility(View.GONE);
            }
            @Override
            public void closeDialog(){
                dialogView.dismiss();
                dialog_background.setVisibility(View.GONE);
            }
        });
        dialogView.showSingleSelectDialog(this, dataList);
        dialog_background.setVisibility(View.VISIBLE);
    }

    private void setAccountType() {
        if (!TextUtils.isEmpty(et_account_type.getText())) {
            if (et_account_type.getText().equals("Cuenta ahorro")) {
                accountType = "1";
            } else if (et_account_type.getText().equals("Cuenta corriente")) {
                accountType = "0";
            } else if (et_account_type.getText().equals("Vista")) {
                accountType = "2";
            } else if (et_account_type.getText().equals("RUT")) {
                accountType = "3";
            }
        }
    }

    private void close() {
        if (getCurrentFocus() == null) {
            return;
        }
        ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }

    private void checkAccountNumber() {
        LogUtils.logE("et_account_type: "+et_account_type.getText() + "et_bank_name: "+et_bank_name.getText());
        if (et_account_type.getText().equals("RUT") &&
                et_bank_name.getText().equals("Banco Estado (Banco del Estado de Chile)")){
            et_account_number.setEnabled(false);
            et_account_number.setTextColor(Color.parseColor("#999999"));
            setDefaultBankCode();
            et_account_number.setInputType(InputType.TYPE_CLASS_TEXT);
            getZiLiPageUserFullInfo(false);
//            tv_tip.setVisibility(View.VISIBLE);
//            lly_bottom_tips.setVisibility(View.GONE);
        } else {
            et_account_number.setEnabled(true);
//            tv_tip.setVisibility(View.GONE);
//            lly_bottom_tips.setVisibility(View.VISIBLE);
            et_account_number.setTextColor(Color.parseColor("#000000"));
            if (et_account_type.getText().equals("Cuenta ahorro")
                    || et_account_type.getText().equals("Cuenta corriente")
                    || et_account_type.getText().equals("Vista")) {
                et_account_number.setFilters(new InputFilter[]{new BankInputFilter()});
                et_account_number.setInputType(InputType.TYPE_CLASS_NUMBER);
                et_account_number.setHint("8-20 dígitos");
            } else if (et_account_type.getText().equals("RUT")) {
                et_account_number.setFilters(new InputFilter[]{new RutInputFilter()});
                et_account_number.setInputType(InputType.TYPE_CLASS_TEXT);
                et_account_number.setHint("7-9 dígitos");
            }
        }
        if (et_account_type.getText().equals("RUT") &&
                et_bank_name.getText().equals("Banco Estado (Banco del Estado de Chile)")) {
            tv_tip.setVisibility(View.VISIBLE);
            tv_tip.setText("\nPara garantizarquelacuenta receptora sea consistente con la persona concédula de identidad, la cuenta RUT no admite modificación, se puede elegir otra cuenta bancaria para recibir el pago.");
            tv_tip.setTextColor(Color.parseColor("#FFB307"));
            Log.e("----","006");
        } else {
            tv_tip.setVisibility(View.GONE);
        }
    }

    public boolean verificationBankAccount(int minLen, int maxLen, String idNumber) {
        if (idNumber.length() < minLen || idNumber.length() > maxLen) {
            return false;
        }

        String prefix = idNumber.substring(0, idNumber.length() - 1);
        char lastChar = idNumber.charAt(idNumber.length() - 1);

        boolean isPrefixDigits = prefix.matches("\\d+");
        boolean isLastCharK = lastChar== 'K';
        boolean isPrefixElevenModAlgorithm = false;
        boolean isAllElevenModAlgorithm = false;
        if (isPrefixDigits) {
            isPrefixElevenModAlgorithm = isElevenModAlgorithm(prefix);
        }

        if (isLastCharK) {
            return isPrefixDigits && isLastCharK && isPrefixElevenModAlgorithm;
        } else {
            if (idNumber.matches("\\d+")) {

                isAllElevenModAlgorithm = isElevenModAlgorithm(idNumber);
                LogUtils.logE(" ---verificationBankAccount--isAllElevenModAlgorithm:"+isAllElevenModAlgorithm);
            }
            return isAllElevenModAlgorithm;
        }
    }

    protected static boolean isElevenModAlgorithm(String str) {
        // 计算11模算法
        int sum = 0;
        for (int i = 0; i < str.length(); i++) {
            int digit = Character.getNumericValue(str.charAt(i));
            sum += (i % 2 == 0) ? digit : -digit;
        }
        return (sum % 11) == 0;
    }

    public boolean verificationBankAccountBase(int minLen, int maxLen, String idNumber) {
        if (idNumber.length() < minLen || idNumber.length() > maxLen) {
            return false;
        }
        return idNumber.matches("\\d{" + minLen + "," + maxLen + "}");
    }

    public boolean verificationIDNumber(int minLen, int maxLen, String idNumber){
        if(idNumber.length()>maxLen || idNumber.length()<minLen){
            return false;
        }
        Pattern pattern = Pattern.compile("[a-zA-Z0-9]+");
        Matcher matcher = pattern.matcher(idNumber);

        return matcher.matches();

    }

    class BankInputFilter implements InputFilter {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

            if (dstart == 0 && source.length() > 0 && source.charAt(0) == ' ') {
                return "";
            }

            int keep = 20 - (dest.length() - (dend - dstart));
            if (keep <= 0) {
                return "";
            } else if (keep >= end - start) {
                return null;
            }
            return null;
        }

    }

    class RutInputFilter implements InputFilter {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

            if (dstart == 0 && source.length() > 0 && source.charAt(0) == ' ') {
                return "";
            }

            int keep = 9 - (dest.length() - (dend - dstart));
            if (keep <= 0) {
                return "";
            } else if (keep >= end - start) {
                return null;
            }
            return null;
        }
    }

    private void setDefaultBankCode() {
        Map<String, String> params = new HashMap<String, String>();
//        showLoading();
        kycModle.getZiLiPagePayBankList(params, new HttpCallback() {
            @Override
            public void onSuccess(@NonNull String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            JSONObject jsonObject = new JSONObject(data);
                            if (kycModle.isSuccess(jsonObject)) {
                                JSONArray dataJa = jsonObject.optJSONArray("data");
                                if (dataJa != null) {
                                    List<SingleSelectBean> selectBeanList = new ArrayList<>();
                                    for (int i = 0; i < dataJa.length(); i++) {
                                        JSONObject dataObject = dataJa.optJSONObject(i);
                                        if (kycModle.getStringToJson(dataObject,
                                                "bankName").equals("Banco Estado (Banco del Estado de Chile)")) {
                                            bankCode = kycModle.getStringToJson(dataObject, "bankCode");
                                            LogUtils.logE("bankCode:"+bankCode);
                                        }
                                    }
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

//                hideLoading();
            }

            @Override
            public void onFaill(@NonNull String e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        T.showShort(AddBandActivity.this, e);
                    }
                });

//                hideLoading();
            }
        });
    }

    private void getZiLiPageUserFullInfo(boolean isInit) {
        Map<String, String> params = new HashMap<String, String>();
        LogUtils.logE("add bank custid:"+ZiLiPageUserDataBean.getInstance().getCustomerId());
        params.put("custId", ZiLiPageUserDataBean.getInstance().getCustomerId());
//        showLoading();
        kycModle.getZiLiPageUserFullInfo(params, new HttpCallback() {
            @Override
            public void onSuccess(@NonNull String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        CapitalInforActivity capitalInforActivity = (CapitalInforActivity) getActivity();
                        try {
                            JSONObject jsonObject = new JSONObject(data);
                            if (kycModle.isSuccess(jsonObject)) {
                                LogUtils.logE(" ->add bank history info getZiLiPageUserFullInfo>" + jsonObject.toString());
                                JSONObject dataJsonObject = jsonObject.optJSONObject("data");
                                String nationalId = dataJsonObject.optString("nationalId");
                                if (nationalId != null) {
                                    mNationalId = nationalId;
                                    String showNationalId = nationalId.substring(0,nationalId.length() -1);
                                    et_account_number.setText(showNationalId);
                                }

                                if (isInit) {
                                    checkAccountNumber();
                                }
                            } else {
                                LogUtils.logE(" ->add bank fail" + jsonObject.toString());
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        T.showShort(getActivity(), kycModle.getStringToJson(jsonObject, "msg"));
                                    }
                                });
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

//                hideLoading();
            }

            @Override
            public void onFaill(@NonNull String e) {
//                hideLoading();
            }
        });
    }

    private class CommonTextWatcher implements TextWatcher {
        private TextView errText;

        private EditText editText;

        public CommonTextWatcher(EditText editText, TextView errText) {
            this.errText = errText;
            this.editText = editText;
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int before, int count) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    String trimmedText = charSequence.toString().trim();

                    if (!trimmedText.isEmpty()) {
                        clearEditTextError();
                    }

                    if (startsWithSpace(charSequence)) {
                        editText.setText(trimmedText);
                        editText.setSelection(trimmedText.length());
                    } else {
                        clearEditTextError();
                    }
                }
            });
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }

        private void clearEditTextError() {
            errText.setVisibility(View.GONE);
        }

        private boolean startsWithSpace(CharSequence charSequence) {
            return charSequence.length() > 0 && charSequence.charAt(0) == ' ';
        }
    }

    @Override
    public void onStop(){
        super.onStop();
//        hideLoading();
    }
}
